package base_05_reflect;

import java.lang.reflect.Method;

/**
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/3/25 10:20
 */
public class MethodDemo {
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("base_05_reflect.Circle");
        Object o = clazz.newInstance();
        System.out.println(">>>>>>getMethod>>>>>");
        Method m1 = clazz.getMethod("draw", int.class, String.class);
        System.out.println(m1.getName());
        Class<?>[] types = m1.getParameterTypes();
        Class<?> returnType = m1.getReturnType();
        System.out.println("返回类型：" + returnType);
        for (Class<?> type : types) {
            System.out.print(type.getSimpleName());
            System.out.println(type.getName());
        }
        System.out.println(">>>>>>getDeclaredMethod>>>>>");
        Method m2 = clazz.getDeclaredMethod("drawCircle");
        System.out.println(">>>>>>invoke>>>>>");
        Object hahahaha = m1.invoke(o, 11, "hahahaha");
        System.out.println("hahha>>>" + hahahaha);
        Class<?> pClazz = clazz.getSuperclass();
        System.out.println(pClazz.getSimpleName());
        Class<?> superClazz = pClazz.getSuperclass();
        System.out.println(superClazz.getSimpleName());
        //Class<?> superclass = superClazz.getSuperclass();
        //System.out.println(superclass.getSimpleName());
        System.out.println(">>>>>>静态方法");
        Method draw = clazz.getMethod("draw", int.class);
        draw.invoke(o, 22);
    }
}

class Shape {
    public void draw() {
        System.out.println("draw");
    }

    public void draw(int count, String name) {
        System.out.println("draw " + name + ",count=" + count);

    }

    public static void draw(int count) {
        System.out.println("count = " + count);
    }

}

class Circle extends Shape {

    private void drawCircle() {
        System.out.println("drawCircle");
    }

    public int getAllCount() {
        return 100;
    }
}